
function [fit,pos,cg,return_R,return_gene]=FTTA_1(pop,maxGen,lb,ub,dim,fobj,PTime)


    [PNumber,MNumber]=size(PTime);  
    stu = 0.2;          %%Study Operator
    com = 0.2;          %%Communication Operator 
    error = 0.001 ;      %%Error Operator (No higher than 0.001)
    teamnumber = 2 ;     %%Team Number Operator(team number>=2 & team number<=pop/4)

    objective=  fobj;      %Objective Function
    [init,Upnew,Lownew] = Initialization1(pop,dim,ub,lb);
    Z = 0;
    
    
    P = cell(maxGen,1);
    gene = cell(pop,1);
    gene2 = cell(pop,1);
    gene3 = cell(pop,1);



    for Iter = 1:maxGen 
        %%Calculate All Fitness Values 
        for i = 1:pop
               
                [a1,a2,a3] =  objective(PTime,init(i,:));
                sol(i,:) = [a1];
                R(i,:) = a2;
                gene{i,1} = a3;

                
        end

        
        %%Find out the Best and the Worst.
        a = find(sol == min(sol));
        b = find(sol == max(sol));
        Best = init(a,:);
        Best = Best(1,:);
        Worst = init(b,:);
        Worst = Worst(1,:);
        init2 = init;
        %% Collective Training
        for i = 1:pop
            a = rand;
            if a>=3/4
                %%Status 1: Moving towards the difference vector between Yourself and the Best
                A = init2(i,:)+rand(1,dim).*(Best-init2(i,:));
                init3(i,:) = [A];
                    else  if  a>=1/2 && a<3/4
                    %%Status 2: Moving towards the difference vector between Yourself and the Best and Worst
                     A = init2(i,:)+rand(1,dim).*(Best-Worst);
                     init3(i,:) = [A];
                     %%Status 3: Moving towards the difference vector between Yourself and the Best while escaping the Worst
                     else  if  a<1/2 && a>=1/4
                       A = init2(i,:)-rand(1,dim).*(Worst-init2(i,:))+rand(1,dim).*(Best-init2(i,:));
                           init3(i,:) = [A];
                           else  if   a<1/4
                           %%Status 4: Player status fluctuation 
                           A = init2(i,:).*(1+trnd(Iter,[1,dim]));
                           init3(i,:) = [A];
                               end
                         end
                   end
            end
        end
        %%Limit Range (Control Boundary)
        for i = 1:pop
            for j = 1:dim
                if init3(i,j)>=Upnew(:,j);
                    init3(i,j) = Upnew(:,j);
                else if init3(i,j)<=Lownew(:,j);
                        init3(i,j) = Lownew(:,j);
                    end
                end
            end
        end
        %% Group training (Striker, Midfielder, Gguard, Goalkeeper)
        X = init3';
        zubie = 4;
        %%EM cluster for grouping
        [label, model, llh] = mixGaussEm(X, zubie);
        Label = label';
        Team1 = init3(find(Label==1),:);
        Team2 = init3(find(Label==2),:);
        Team3 = init3(find(Label==3),:);
        Team4 = init3(find(Label==4),:);
        %%Calculate the size of each group
        [M1,N1] = size(Team1);
        [M2,N2] = size(Team2);
        [M3,N3] = size(Team3);
        [M4,N4] = size(Team4);
        M5 = [M1,M2,M3,M4];
        %%We assume that if the number of people in a group is less than teamnumber, we cannot communicate.
        for k = 1:4
            if M5(:,k)<=teamnumber
                %%Do the  random grouping at this time
              [Team1,Team2,Team3,Team4] = suijifenzu(init3,pop);
              break 
            end    
        end
        %%Update the size of each group
        [M1,N1] = size(Team1);
        [M2,N2] = size(Team2);
        [M3,N3] = size(Team3);
        [M4,N4] = size(Team4);
        %%Learning and communication within each group (communication and learning)
         [team1] = study_1(Team1,M1,stu,com,error,dim,objective,Upnew,Lownew,teamnumber,PTime);
         [team2] = study_1(Team2,M2,stu,com,error,dim,objective,Upnew,Lownew,teamnumber,PTime);
         [team3] = study_1(Team3,M3,stu,com,error,dim,objective,Upnew,Lownew,teamnumber,PTime);
         [team4] = study_1(Team4,M4,stu,com,error,dim,objective,Upnew,Lownew,teamnumber,PTime);
        %%Regroup
        init4 = [team1;team2;team3;team4]; 
        %%Calculate fitness
        for i = 1:pop
                [a6,a11,a22] =  objective(PTime,init4(i,:));
                sol2(i,:) = [a6];
                R2(i,:) = a11;
                gene2{i,1} = a22;
        end 
        %%Update players and update corresponding fitness
        for i = 1:pop
            if sol(i,:)<=sol2(i,:)
                init4(i,:) = init(i,:); sol2(i,:) = sol(i,1);
                R2(i,:) = R(i,:);
                gene2{i,1} = gene{i,1};
            end
        end
        sol3 =sol2;
        R3 = R2;
        gene3 = gene2;
        %%Find the best player.
        d = find(sol3 == min(sol3));
        d = d(1,:);
        Best2 = init4(d,:);
        Best2 = Best2(1,:);
        best2 = min(sol3);
        best2=  best2(1,:);
        best2_R2 = R3(d,:);
        best2_gene2 = gene3{d,1};
        % For random objective function
        if Iter>1
            if  best2>M(Iter-1,:)
                best2 = M(Iter-1,:);
                Best2 = N(Iter-1,:);
                best2_R2 = O(Iter-1,:);
                best2_gene2 = P{Iter-1,1};
            end
        end
        %%individual Extra Training
            Best3 = Best2.*(1+(1-1/Iter)*randn+(1/Iter)*cauchy(1));
        %%Boundary control
        for i = 1:dim   
                if Best3(:,i)>=Upnew(:,i);
                    Best3(:,i) = Upnew(:,i);
                else if Best3(:,i)<=Lownew(:,i);
                        Best3(:,i) = Lownew(:,i);            
                end
            end
        end
        %%Calculate the target value
        [best3,best3_R3,best3_gene3] = objective(PTime,Best3);
        %%Best player replacement
        if  best3<best2
            best2 = best3;
            Best2 = Best3;
            best2_R2 = best3_R3;
            best2_gene2 = best3_gene3;

            init4([d],:) = [Best3];
        end
        Z = Z+1;
        M(Z,:) = [best2];
        N(Z,:) = [Best2];
        O(Z,:) = best2_R2;
        P{Z,:} = best2_gene2;
        %%Update the team members
        init = init4;
   
        cg(Iter) = M(Z,:);
        

     end
    [fit,index] = min(cg);
    pos = N(index,:);
    return_R = O(index,:);
    return_gene = P{index,:};

 end















